package com.tonyodev.fetchapp.fetch2;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;

import com.tonyodev.fetch2.FetchConfiguration;
import com.tonyodev.fetch2.HttpUrlConnectionDownloader;
import com.tonyodev.fetch2.NetworkType;
import com.tonyodev.fetch2core.Downloader;
import com.tonyodev.fetch2core.FetchLogger;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class FetchBuilderTest {
    Context appContext;
    @Before
    public void setUp() throws Exception {
        appContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void hasCorrectFetchPreferences() throws Exception {
        final String namespace = "_fetch_";
        final int bufferSize = 1;
        final boolean loggingEnabled = true;
        final long progressInterval = 10;
        final int concurrentLimit = 2000;
        final NetworkType networkType = NetworkType.WIFI_ONLY;
        final FetchLogger logger = new FetchLogger();
        final HttpUrlConnectionDownloader downloader = new HttpUrlConnectionDownloader(Downloader.FileDownloaderType.SEQUENTIAL);
        final boolean enableInMemoryDatabase = true;
        final FetchConfiguration.Builder builder =
            new FetchConfiguration.Builder(appContext)
                .setNamespace(namespace)
                .enableLogging(loggingEnabled)
                .setProgressReportingInterval(progressInterval)
                .setGlobalNetworkType(networkType)
                .setDownloadConcurrentLimit(concurrentLimit)
                .setLogger(logger)
                .setHttpDownloader(downloader);
        final FetchConfiguration prefs = builder.build();
        assertEquals(namespace, prefs.getNamespace());
        assertEquals(loggingEnabled, prefs.getLoggingEnabled());
        assertEquals(progressInterval, prefs.getProgressReportingIntervalMillis());
        assertEquals(concurrentLimit, prefs.getConcurrentLimit());
        assertEquals(networkType, prefs.getGlobalNetworkType());
        assertEquals(logger, prefs.getLogger());
        assertEquals(downloader, prefs.getHttpDownloader());
    }
}